﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace Web.Views.Common
{
    public partial class deleteTicket : System.Web.UI.Page
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
           
                if (Request["mobile"] != null && Request["email"]!=null)
                {
                   string  mobile = Request.Form["mobile"];
                   string email = Request.Form["email"];
                    //Session["del_mobile"] = mobile;
                    //Session["del_email"] = email;
                   if (!mobile.Contains("电话"))
                         CustomerBindData(mobile, email);
                }
                //else if (Session["del_mobile"] != null && Session["del_email"] != null)
                //{

                //}

        }

        private void CustomerBindData(string _mobile, string _email)
        {
            string str = string.Format(" Telphone='{0}' and Email='{1}' and IsDel = 0", _mobile,_email);
                    DataSet ds = (new Easydp.Controllers.TransferTicketController()).GetData(str);
                        //if (ds.Tables[0].Rows.Count <= 0)
                        //{
                        //   // Response.Write("<script>alert('你没有信息可删除');window.location.herf='TransferTicket.aspx'</script>");
                        //    divLogin.Style.Value = "display:black";
                        //    divTicketList.Style.Value = "display:none";
                        //}
                        //else
                        //{
                        //    spanCount.InnerText = ds.Tables[0].Rows.Count.ToString();
                        //    dgvDelTicket.DataSource = ds.Tables[0];
                        //    dgvDelTicket.DataBind();
                        //    divLogin.Style.Value = "display:none";
                        //    divTicketList.Style.Value = "display:black";
                        //}
                    spanCount.InnerText = ds.Tables[0].Rows.Count.ToString();
                    dgvDelTicket.DataSource = ds.Tables[0];
                    dgvDelTicket.DataBind();
                    divLogin.Style.Value = "display:none";
                    divTicketList.Style.Value = "display:black";

        }
        public static string GetPastTime(string caption)
        {
            //string caption = "2009-05-05 13:27:20";
            DateTime d1 = DateTime.Parse(caption);

            DateTime d2 = DateTime.Parse(DateTime.Now.ToLongTimeString());

            System.TimeSpan ND = d2 - d1;

            int n = ND.Days;   //天数差

            int hn = ND.Hours; //小时差
            int m = ND.Minutes;// 分钟差

            string res;


            if (n == 0 && hn == 0)
            {
                res = m.ToString() + "分钟前";
            }
            else if (n == 0 && hn > 0)
            {
                res = hn.ToString() + "时" + m.ToString() + "分钟前";
            }
            else
            {
                res = n.ToString() + "天" + hn.ToString() + "时" + m.ToString() + "分钟前";
            }
            return res;
        }

    protected void dgvDelTicket_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "del":
                {
                    string[] str = e.CommandArgument.ToString().Split('^');
                    string strID = str[0];
                    string mobile = str[2];
                    string email = str[1];

                    if ((new Easydp.Controllers.TransferTicketController()).Delete(strID))
                    {
                        Response.Write("<script>alert('删除成功')</script>");
                        CustomerBindData(mobile, email);
                    }
                    else
                        Response.Write("<script>alert('删除失败，稍后重试')</script>");
                    break;
                }
            default:
                break;
        }
    } 
    }
}
